package com.ling.springbootinit.common;

/**
 * 返回工具类
 */
public class ResultUtils {

    /**
     * 成功
     */
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, "ok");
    }


    public static <T> SongResponse<T> successSong(T result) {
        return new SongResponse<>(0, result, "ok");
    }
    public static <T,E> SongDetailResponse<T, E> successSongD(T result, E result2) {
        return new SongDetailResponse<>(0, result, result2);
    }

    public static <T,E> SongCommentResponse<T, E> successSongC(T hotComments, E topComments, int total) {
        return new SongCommentResponse<>(0, true, hotComments, topComments,total);
    }

    public static <T> WeatherResponse<T> successWeather(T data) {
        return new WeatherResponse<>(data, 0, "ok");
    }

    /**
     * 失败
     *
     * @param errorCode
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode) {
        return new BaseResponse<>(errorCode);
    }

    /**
     * 失败
     *
     * @param code
     * @param message
     * @return
     */
    public static BaseResponse error(int code, String message) {
        return new BaseResponse(code, null, message);
    }

    /**
     * 失败
     *
     * @param errorCode
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode, String message) {
        return new BaseResponse(errorCode.getCode(), null, message);
    }
}
